package logic

import (
	"context"
	"shops/model/redis"
	"shops/shoprpc/internal/svc"
	"shops/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LikeListLogic {
	return &LikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LikeListLogic) LikeList(in *shoprpc.LikeListRequest) (*shoprpc.LikeListResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Rdb.ZRangeWithScores("like", 0, 9)

	var like []*shoprpc.Like
	for _, s := range scores.Val() {
		s2 := shoprpc.Like{
			Name: s.Member.(string),
			Like: int64(s.Score),
		}
		like = append(like, &s2)
	}
	return &shoprpc.LikeListResponse{Like: like}, nil
}
